<html>
<!-- Head tag -->
<head><meta name="generator" content="Hexo 3.9.0">

    <meta name="google-site-verification" content="uxeL3ivCjEkmCPEWS1owNMkK9VHPxOMCjcaMHaQ38Bo">
    <meta name="google-site-verification" content="yU7d61qsV4eAvSOazt85VJMYfiEDjZjcaXwyQKGP5Bc">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	
	
		<link href="/favicon.ico" rel="icon">
	 
      <title>Enable notification plugin in KDE Connect on macOS | Inoki in KDE</title>
	<link rel="stylesheet" href="/css/font-awesome/css/font-awesome.css">
	<link rel="stylesheet" href="/css/style.css">
	<link rel="stylesheet" href="/css/highlight.css">
	
	
<!-- Google Analytics -->
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-108089983-2"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-108089983-2');
</script>

<!-- End Google Analytics -->

<!-- Google Adsense -->
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
  (adsbygoogle = window.adsbygoogle || []).push({
    google_ad_client: "ca-pub-2713518338457470",
    enable_page_level_ads: true
  });
</script>


</head>
<body>
	<div id="site" class="site">
		<div id="sidebar" class="sidebar">
			<header id="header" class="site-header">
	<div class="site-branding">
		<h1 class="site-title">
			
				<a href="/images/avatar-small.png" class="avatar-circle"><img src="/images/avatar-small.png" /></a>
			
			<a href="/" rel="home">Inoki ❤️ KDE</a></h1>
		<p class="site-description"></p>
		<button class="secondary-toggle font-asesome-icon">Menu and widgets</button>
	</div>
</header>
<div id="secondary" class="secondary">
	<nav class="main-navigation">
                         <ul id="menu-demo-menu" class="nav-menu">
						 
							<li class="menu-item"><a href="/">Home</a></li>
						
							<li class="menu-item"><a href="/archives">Archives</a></li>
						
							<li class="menu-item"><a href="/about">AboutMe</a></li>
						
                         </ul>
    </nav>
	
		<aside class="widget social-navigation">
    <ul>
        <li>
            <a href="http://twitter.com/IIInoki">
                <i class="fa fa-twitter" aria-hidden="true"></i>
            </a>
        </li>
        <li>
            <a href="https://www.facebook.com/noki.noki.10">
                <i class="fa fa-facebook-square" aria-hidden="true"></i>
            </a>
        </li>
        <li>
            <a href="https://github.com/inokinoki">
                <i class="fa fa-github" aria-hidden="true"></i>
            </a>
        </li>
        <li>
            <a href="https://linkedin.com/in/weixuan-xiao-032725108/">
                <i class="fa fa-linkedin" aria-hidden="true"></i>
            </a>
        </li>
    </ul>
</aside>
	
		
<aside class="widget">
		<h3 class="widget-title">Recent Posts</h3>		
		<ul>
			
          <li>
            <a href="/2019/09/01/KDE-Connect-macOS-GSoC-Final-Release/">KDE Connect macOS Release</a>
          </li>
        
          <li>
            <a href="/2019/07/24/DBus/">DBus connection on macOS</a>
          </li>
        
          <li>
            <a href="/2019/07/18/KDE-Connect-macOS-plugin-notification/">Enable notification plugin in KDE Connect on macOS</a>
          </li>
        
          <li>
            <a href="/2019/07/16/KDE-Connect-macOS/">Connect your Android phone with your Mac via KDE Connect</a>
          </li>
        
          <li>
            <a href="/2019/05/26/Craft-packager/">KDE Craft Packager on macOS</a>
          </li>
        
		</ul>
	</aside>


	
		
  <aside class="widget">
		<h3 class="widget-title">Tag Cloud</h3>
        <a href="/tags/Craft/" style="font-size: 13.33px;">Craft</a> <a href="/tags/DBus/" style="font-size: 10px;">DBus</a> <a href="/tags/GSoC/" style="font-size: 16.67px;">GSoC</a> <a href="/tags/Inoki/" style="font-size: 10px;">Inoki</a> <a href="/tags/KDE-Connect/" style="font-size: 16.67px;">KDE Connect</a> <a href="/tags/macOS/" style="font-size: 20px;">macOS</a>
    </aside>

	
</div>

		</div>
		<div id="content" class="site-content">
			<main id="main" class="site-main" role="main">
				
<article class="hentry ">
		
		
			<header class="entry-header">
				<h2 class="entry-title"><a class="post-title-link" href="/2019/07/18/KDE-Connect-macOS-plugin-notification/" rel="bookmark">Enable notification plugin in KDE Connect on macOS</a></h2>	
			</header>
		
		<!-- .entry-header -->
		<div class="entry-content">
			
				<p>You may have tried KDE Connect for macOS. </p>
<p>If you’ve not yet tried KDE Connect, you can read my post: <a href="/2019/07/16/KDE-Connect-macOS/">Connect your Android phone with your Mac via KDE Connect</a></p>
<p>As I mentioned, this post will help you to build your own KDE Connect with native Notification support for macOS.</p>
<img src="/2019/07/18/KDE-Connect-macOS-plugin-notification/notification-preview.gif" title="Notification Preview">
<h1 id="Build"><a href="#Build" class="headerlink" title="Build"></a>Build</h1><p>This post will not give you instructions of building KDE Connect on macOS because there is already a page on <a href="https://community.kde.org/KDEConnect/Build_MacOS" target="_blank" rel="noopener">KDE Connect Wiki</a></p>
<p>If you met any problems, you can submit them on our <a href="https://bugs.kde.org/enter_bug.cgi?product=kdeconnect" target="_blank" rel="noopener">KDE bug tracker</a></p>
<h1 id="Add-notification-support"><a href="#Add-notification-support" class="headerlink" title="Add notification support"></a>Add notification support</h1><p>Notification plugin depends on <code>KNotification</code>. There is no native support for macOS in this library. </p>
<p>I’ve made a native one and it has been submited as a patch. But it takes time to get reviewed and optimized.</p>
<p>I keep the patch available on a repo of my GitHub:<br><a href="https://github.com/Inokinoki/knotifications" target="_blank" rel="noopener">https://github.com/Inokinoki/knotifications</a>. So, <code>Craft</code> can access it and compile it to provide support of macOS Notification.</p>
<p>But we’re looking forward to its delivery in <code>KNotification</code>.</p>
<p>What you need to do is very simple:</p>
<ol>
<li>Find KNotifications blueprint file</li>
</ol>
<ul>
<li>Enter your <code>CraftRoot</code> folder. To me, it’s <code>/Users/inoki/CraftRoot</code>. </li>
<li>Enter <code>etc</code> -&gt; <code>blueprints</code> -&gt; <code>locations</code> -&gt; <code>craft-blueprints-kde</code> folder.</li>
<li>Open <code>kde/frameworks/tier3/knotifications/knotifications.py</code>.</li>
</ul>
<ol start="2">
<li><p>Remove <code>self.versionInfo.setDefaultValues()</code> in <code>setTargets</code> of <code>subinfo</code> class. If you’re not familiar with <code>python</code>, just find this line and delete it.</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">self.versionInfo.setDefaultValues()</span><br></pre></td></tr></table></figure>
</li>
<li><p>Add these 2 lines:</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">self.svnTargets[<span class="string">'master'</span>] = <span class="string">'https://github.com/Inokinoki/knotifications.git'</span></span><br><span class="line">self.defaultTarget = <span class="string">'master'</span></span><br></pre></td></tr></table></figure>
</li>
</ol>
<p>The file should look like this:</p>
<img src="/2019/07/18/KDE-Connect-macOS-plugin-notification/preview.png" title="knotification blueprint preview">
<p>After that, rebuild KDE Connect with Craft.</p>
<p>If everything is ok, launch your KDE Connect.</p>
<p>You could receive notifications from your phone or your other computers(if well configured), just like this:</p>
<img src="/2019/07/18/KDE-Connect-macOS-plugin-notification/notification.png" title="Test Notification">
<p>You can also change notification settings of KDE Connect in your macOS Notification Center. By default, the notification style is <code>Bar</code>, set it to <code>Alert</code> to see quick actions to your notifications.</p>
<h4 id="Notice-Currently-there-is-a-bug-you-may-receive-duplicated-notifications-We’re-figuring-out-its-reason-and-it-will-be-fixed-as-soon-as-possible"><a href="#Notice-Currently-there-is-a-bug-you-may-receive-duplicated-notifications-We’re-figuring-out-its-reason-and-it-will-be-fixed-as-soon-as-possible" class="headerlink" title="Notice: Currently there is a bug, you may receive duplicated notifications. We’re figuring out its reason and it will be fixed as soon as possible."></a>Notice: Currently there is a bug, you may receive duplicated notifications. We’re figuring out its reason and it will be fixed as soon as possible.</h4><p>Thanks for your reading and your support to KDE Connect :)</p>
<p>If you’d like to, you can also follow me on GitHub :)</p>
<h1 id="For-pros"><a href="#For-pros" class="headerlink" title="For pros"></a>For pros</h1><p>For developers, if you’re familiar with diff, just apply this diff patch:<br><figure class="highlight diff"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">diff --git a/kde/frameworks/tier3/knotifications/knotifications.py b/kde/frameworks/tier3/knotifications/knotifications.py</span><br><span class="line">index 9b46044..f5c82a4 100644</span><br><span class="line"><span class="comment">--- a/kde/frameworks/tier3/knotifications/knotifications.py</span></span><br><span class="line"><span class="comment">+++ b/kde/frameworks/tier3/knotifications/knotifications.py</span></span><br><span class="line">@@ -3,7 +3,8 @@ import info</span><br><span class="line"> </span><br><span class="line"> class subinfo(info.infoclass):</span><br><span class="line">     def setTargets(self):</span><br><span class="line"><span class="deletion">-        self.versionInfo.setDefaultValues()</span></span><br><span class="line"><span class="addition">+        self.svnTargets['master'] = 'https://github.com/Inokinoki/knotifications.git'</span></span><br><span class="line"><span class="addition">+        self.defaultTarget = 'master'</span></span><br><span class="line">         self.patchToApply['5.57.0'] = [("disabled-deprecated-before.patch", 1)]</span><br><span class="line"> </span><br><span class="line">         self.description = "TODO"</span><br></pre></td></tr></table></figure></p>

			
		</div><!-- .entry-content -->
		
		
			<div class="entry-comments">
				 
      <div id="disqus_thread"></div>
    <script type="text/javascript">
    /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
    var disqus_shortname = 'inokinoki-kde'; // required: replace example with your forum shortname

    /* * * DON'T EDIT BELOW THIS LINE * * */
    (function() {
      var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
      dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
      (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();
  </script>
  <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
  
  
   
			</div>
		
		<footer class="entry-footer">
			<span class="posted-on font-asesome-icon">
	<a href="" rel="bookmark">
	<time class="updated" datetime="2019-07-18T14:09:22.000Z">2019-07-18</time>
	</a>
</span>

	<span class="cat-links font-asesome-icon">
		
				<a href="/categories/KDE-Connect/" rel="category tag">KDE Connect</a>
		
				<a href="/categories/KDE-Connect/macOS/" rel="category tag">macOS</a>
		
	</span>


	<span class="tags-links font-asesome-icon">
	
		<a href="/tags/macOS/" rel="category tag">macOS</a>
    
		<a href="/tags/KDE-Connect/" rel="category tag">KDE Connect</a>
    
		<a href="/tags/GSoC/" rel="category tag">GSoC</a>
    
</span>
		

    <span class="eye font-asesome-icon" >
         <span id="/2019/07/18/KDE-Connect-macOS-plugin-notification/" class="leancloud_visitors" data-flag-title="Enable notification plugin in KDE Connect on macOS">
        
        </span>
    </span>

			<br/>
			<a href="https://www.vultr.com/?ref=7746405"><img src="https://www.vultr.com/media/banner_1.png" width="728" height="90"></a>
		</footer><!-- .entry-footer -->
</article>
<div class="misc">
    <a href="#main"><span class="top font-asesome-icon">Top</span></a>
</div>
			</main>
		</div>
		<footer id="colophon" class="site-footer">
			<div class="site-info">
				<span>powered by <a href="https://hexo.io/">Hexo</a>&nbsp;&nbsp; theme by <a href="https://github.com/Troy-Yang/hexo-theme-twentyfifteen-wordpress">Troy</a> &nbsp; inspired by <a href="https://wordpress.org/themes/">wordpress</a></span>
			</div><!-- .site-info -->
		</footer>
	</div>
	<!-- <div id="infinite-footer">
            <div class="container">
                <div class="blog-info">
                    <a id="infinity-blog-title" href="#" rel="home" title="Scroll back to top">
                         Happy Coding, Happy Life!
                    </a>
                </div>
                <div class="blog-credits">
					<span>蜀ICP备15004900号-1</span>
                </div>
            </div>
        </div>#infinite-footer -->
    <!-- After footer scripts -->
    <script src="/js/jquery-3.1.1.min.js"></script>
<script src="/js/main.js"></script>

    <!--referring from https://notes.wanghao.work/2015-10-21-%E4%B8%BANexT%E4%B8%BB%E9%A2%98%E6%B7%BB%E5%8A%A0%E6%96%87%E7%AB%A0%E9%98%85%E8%AF%BB%E9%87%8F%E7%BB%9F%E8%AE%A1%E5%8A%9F%E8%83%BD.html -->
    <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
    <script>
        AV.initialize("QC5aQ8pUah279L1skNerLRTU-gzGzoHsz", "mhvEFRRIuPHtjNgOXAe9axsk");
    </script>
    <script>
        function showTime(Counter) {
            var query = new AV.Query(Counter);
            $(".leancloud_visitors").each(function () {
                var url = $(this).attr("id").trim();
                query.equalTo("url", url);
                query.find({
                    success: function (results) {
                        if (results.length == 0) {
                            var content = $(document.getElementById(url)).text() + ': 0';
                            $(document.getElementById(url)).text(content);
                            return;
                        }
                        for (var i = 0; i < results.length; i++) {
                            var object = results[i];
                            //var content = $(document.getElementById(url)).text() + ': ' + object.get('time');
                            $(document.getElementById(url)).text(object.get('time'));
                        }
                    },
                    error: function (object, error) {
                        console.log("Error: " + error.code + " " + error.message);
                    }
                });
            });
        }
        function addCount(Counter) {
            var Counter = AV.Object.extend("Counter");
            url = $(".leancloud_visitors").attr('id').trim();
            title = $(".leancloud_visitors").attr('data-flag-title').trim();
            var query = new AV.Query(Counter);
            query.equalTo("url", url);
            query.find({
                success: function (results) {
                    if (results.length > 0) {
                        var counter = results[0];
                        counter.fetchWhenSave(true);
                        counter.increment("time");
                        counter.save(null, {
                            success: function (counter) {
                                //var content = $(document.getElementById(url)).text() + ': ' + counter.get('time');
                                // remove ': '
                                $(document.getElementById(url)).text(counter.get('time'));
                            },
                            error: function (counter, error) {
                                console.log('Failed to save Visitor num, with error message: ' + error.message);
                            }
                        });
                    } else {
                        var newcounter = new Counter();
                        newcounter.set("title", title);
                        newcounter.set("url", url);
                        newcounter.set("time", 1);
                        newcounter.save(null, {
                            success: function (newcounter) {
                                console.log("newcounter.get('time')=" + newcounter.get('time'));
                                var content = $(document.getElementById(url)).text() + ': ' + newcounter.get('time');
                                // remove ': '
                                $(document.getElementById(url)).text(newcounter.get('time'));
                            },
                            error: function (newcounter, error) {
                                console.log('Failed to create');
                            }
                        });
                    }
                },
                error: function (error) {
                    console.log('Error:' + error.code + " " + error.message);
                }
            });
        }
        $(function () {
            var Counter = AV.Object.extend("Counter");
            if ($('.leancloud_visitors').length == 1) {
                addCount(Counter);
            } else if ($('.post-title-link').length > 1) {
                showTime(Counter);
            }
        });
    </script>
    

</body>
</html>